library f_component;

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:whale/helper/utils/util.dart';

export 'carousel_text.dart';
export 'nodata.dart';
export 'dash_line.dart';

class TPSliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
  final double max;
  final double min;
  final Color? floatColor;
  final Widget Function(double) builder;
  TPSliverPersistentHeaderDelegate({
    required this.builder,
    required this.max,
    required this.min,
    this.floatColor,
  });

  @override
  Widget build(
      BuildContext context, double shrinkOffset, bool overlapsContent) {
    return Container(
      color: shrinkOffset > 0 ? floatColor : Colors.white,
      child: builder(shrinkOffset),
    );
  }

  @override
  double get maxExtent => max;

  @override
  double get minExtent => min;

  @override
  bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) {
    return false;
  }
}

void showFilterDate({
  Function(DateTimeRange)? complete,
}) {
  Get.bottomSheet(
    SingleChildScrollView(
      child: Container(
        padding: EdgeInsets.only(top: 20.sp),
        clipBehavior: Clip.antiAlias,
        decoration: const BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.0),
            topRight: Radius.circular(20.0),
          ),
        ),
        child: Column(
          children: [
            BrnCalendarView(
              showControllerBar: true,
              displayMode: DisplayMode.month,
              selectMode: SelectMode.range,
              rangeDateChange: complete,
            ),
            SafeArea(
              child: Container(
                margin: EdgeInsets.only(top: 10.sp, bottom: 5.sp),
                width: Get.width / 5 * 4,
                child: ElevatedButton(
                  onPressed: () {
                    Get.back();
                  },
                  style: ElevatedButton.styleFrom(
                    primary: Color(0xff58C165),
                    shape: StadiumBorder(),
                  ),
                  child: Text("确定"),
                ),
              ),
            ),
          ],
        ),
      ),
    ),
    // 底部颜色为透明，用Container修饰顶部圆角
    backgroundColor: Colors.transparent,
    isScrollControlled: true,
  );
}
